package com.xiaode.controller.app.task.activity;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.BooleanV;
import com.xiaode.common.anotation.JSONArrayString;
import com.xiaode.common.anotation.UserType;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;

import java.util.Date;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;

@Path("/activity")
@Api("活动任务模块")
@EnableCORS
public class ActivityController extends Controller {
	
    @Inject
    ActivityService service;


    @ApiOper("查询首页活动列表")
    public void getActivityPage(
    		@NotBlank @ApiPara(value = "haveMe", notes = "是否要查询自己的完成情况") Boolean haveMe,
    		@ApiPara(value = "state", notes = "0未审核,1已审核(isExamine=true时必填)") Integer state,
    		@BooleanV @ApiPara(value = "isExamine", notes = "是否是审核查询")Boolean isExamine,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
    		@NotEmpty @Size(min = 0, max = 50) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception {
    	Integer accountId = getAttr("accountId");//学生时需要这个参数
    	Integer userTypeMy = getAttr("userType");
        Ret ret = service.getActivityPage(accountId, userTypeMy, haveMe, state, isExamine, page, limit);
        renderJson(ret);
    }

    @ApiOper("查询某个学生已审核的活动列表（个人页面）")
    public void getUserActivityPage(
            @ApiPara(value = "accountId", notes = "账号id") Integer accountId,
            @NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
            @NotEmpty @Size(min = 0, max = 50) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception {
        Ret ret = service.getUserActivityPage(accountId, page, limit);
        renderJson(ret);
    }
    
    @ApiOper("查询老师发布的活动")
    public void getActivityPageByPublicer(
    		@Size @ApiPara(value = "accountId",notes = "发布人账号id")Integer accountId,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
    		@NotEmpty @Size(min = 0, max = 50) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception {
        Ret ret = service.getActivityPageByPublicer(accountId, page, limit);
        renderJson(ret);
    }
    
    @ApiOper("活动详情")
    public void getActivityInfo(@Size @ApiPara(value = "activityId",notes = "任务id")Integer activityId)throws Exception{
        Ret ret = service.getActivityInfo(activityId);
        renderJson(ret);
    }
    
    @ApiOper("查询某个学生某个的活动参与情况")
    public void getActivityUserJoinInfo(
    		@Size @ApiPara(value = "activityId",notes = "活动id")Integer activityId,
    		@Size @ApiPara(value = "accountId",notes = "参与人账号id")Integer accountId)throws Exception{
        Ret ret = service.getActivityUserJoinInfo(activityId, accountId);
        renderJson(ret);
    }
    
    @ApiOper("学生报名情况")
    public void getUserEnrollInfo(
    		@Size @ApiPara(value = "activityId",notes = "活动id")Integer activityId,
    		@Size @ApiPara(value = "accountId",notes = "参与人账号id")Integer accountId)throws Exception{
        Ret ret = service.getUserEnrollInfo(activityId, accountId);
        renderJson(ret);
    }

    @ApiOper("发布活动")
    public void publishActivity(
            @Size(max = 200) @ApiPara(value = "title", notes = "标题") String title,
            @Size(max = 500) @ApiPara(value = "content", notes = "活动内容") String content,
            @ApiPara(value = "department", notes = "部门") String department,
            @JSONArrayString @ApiPara(value = "files", notes = "文件[{type:xxx,url:xxx},{type:xxx,url:xxx}]") String files,
            @Size @ApiPara(value = "score", notes = "积分") Integer score,
            @NotBlank @ApiPara(value = "endDate", notes = "结束日期") Date endDate,
            @ApiPara(value = "typeName", notes = "类型名称") String typeName) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
        Ret ret = service.publishActivity(accountId, userType, title, content, department, files, score, endDate, typeName);
        renderJson(ret);
    }

    @ApiOper("修改活动")
    public void updateActivity(
    		@Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId,
    		@ApiPara(value = "title", notes = "标题") String title,
    		@Size @ApiPara(value = "content", notes = "活动内容") String content,
    		@ApiPara(value = "department", notes = "部门") String department,
    		@JSONArrayString @ApiPara(value = "files", notes = "文件[{type:xxx,url:xxx},{type:xxx,url:xxx}]") String files,
    		@Size @ApiPara(value = "score", notes = "积分") Integer score,
    		@NotBlank @ApiPara(value = "endDate", notes = "结束日期") Date endDate,
            @ApiPara(value = "typeName", notes = "类型名称") String typeName) throws Exception {
    	Integer userType = getAttr("userType");
        Ret ret = service.updateActivity(userType, title, content, department, files, score, activityId, endDate, typeName);
        renderJson(ret);
    }
    
    @ApiOper("老师删除自己发布的活动")
    public void deleteUserPublicActivity(@Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
        Ret ret = service.deleteUserPublicActivity(accountId, userType, activityId);
        renderJson(ret);
    }

    @ApiOper("活动报名")
    public void signUpActivity(
    		@Size @ApiPara(value = "name", notes = "姓名") String name,
    		@Size @ApiPara(value = "clasId", notes = "班级") String clas,
    		@Size @ApiPara(value = "mbtiPersonality", notes = "mbti人格") String mbtiPersonality,
    		@Size @ApiPara(value = "describe", notes = "个人简介") String describe,
           	@Size @ApiPara(value = "activityId", notes = "活动Id") Integer activityId) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
        Ret ret = service.signUpActivity(accountId, userType, name, clas, mbtiPersonality, describe, activityId);
        renderJson(ret);
    }

    @ApiOper("学生上传活动参与情况")
    public void participationActivity(
    		@JSONArrayString @ApiPara(value = "files", notes = "文件[{type:xxx,url:xxx},{type:xxx,url:xxx}]") String files,
    		@Size @ApiPara(value = "description", notes = "作品描述") String description,
    		@Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
        Ret ret = service.participationActivity(accountId, userType, files, description, activityId);
        renderJson(ret);
    }

    @ApiOper("发表活动心得")
    public void publishRealize(
    		@Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId,
    		@Size @ApiPara(value = "content", notes = "心得") String content,
    		@BooleanV @ApiPara(value = "isShare", notes = "是否分享") Boolean isShare) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.publishRealize(accountId, activityId, content, isShare);
        renderJson(ret);
    }

    @ApiOper("老师查询所有活动中待审核的数量")
    @UserType(conType = {1})
    public void getWaitExamineTotal() throws Exception {
        Ret ret = service.getWaitExamineTotal();
        renderJson(ret);
    }

    @ApiOper("老师查询所有做某个活动的学生以及统计数量")
    @UserType(conType = {1})
    public void getActivityAllStudentList(@Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId) throws Exception {
        Ret ret = service.getActivityAllStudentList(activityId);
        renderJson(ret);
    }
    
    @ApiOper("老师查询某个活动的每个学生完成的具体情况")
    @UserType(conType = {1})
    public void getActivityStudentList(
    		@Size @ApiPara(value = "state", notes = "状态 0.未审核 1.已审核") Integer state,
            @Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId) throws Exception {
        Ret ret = service.getActivityStudentList(state, activityId);
        renderJson(ret);
    }

    @ApiOper("审核活动")
    public void examineActivity(
    		@Size @ApiPara(value = "activityUserId", notes = "活动完成id") Integer activityUserId,
    		@Size @ApiPara(value = "score", notes = "评价分（星）") Integer score,
    		@Size(min = 0, max = 200) @ApiPara(value = "content", notes = "评价内容") String content,
    		@Size(min = 0, max = 10) @ApiPara(value = "evaluation", notes = "教师评分（分）") Integer evaluation,
    		@ApiPara(value = "medalName", notes = "勋章名称") String medalName) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
        Ret ret = service.examineActivity(accountId, userType, score, content, evaluation, activityUserId, medalName);
        renderJson(ret);
    }
    
    @ApiOper("查询某个活动的学生排名")
    public void getActivityUserRanking(
    		@Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId,
    		@BooleanV @ApiPara(value = "isAdmin", notes = "是否是管理发布(false:点击banner时，true:活动审核时)") Boolean isAdmin) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.getActivityUserRanking(accountId, activityId, isAdmin);
        renderJson(ret);
    }
    
    @ApiOper("首页活动排行Banner")
    public void getActivityUserRankingBanner() throws Exception {
        Ret ret = service.getActivityUserRankingBanner();
        renderJson(ret);
    }
    
    @ApiOper("发布/撤销活动排名结果")
    public void publicActivityUserRanking(@Size @ApiPara(value = "activityId", notes = "活动id") Integer activityId) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.publicActivityUserRanking(accountId, activityId);
        renderJson(ret);
    }
    
    
    
    @ApiOper("获取用户勋章")
    public void getUserMedalList(@Size @ApiPara(value = "accountId", notes = "用户账号id") Integer accountId) throws Exception {
        Ret ret = service.getUserMedalList(accountId);
        renderJson(ret);
    }
    
    @ApiOper("获取勋章列表")
    public void getMedalList() throws Exception {
        Ret ret = service.getMedalList();
        renderJson(ret);
    }
    
    

}
